package com.yyhn.gulimall.search.web;

import com.yyhn.gulimall.search.service.MallSearchService;
import com.yyhn.gulimall.search.vo.SearchParam;
import com.yyhn.gulimall.search.vo.SearchResult;
import org.elasticsearch.search.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    MallSearchService mallSearchService;
    @GetMapping("list.html")
    public String index(SearchParam searchParam, Model model, HttpServletRequest request){

        searchParam.set_queryString(request.getQueryString());
        SearchResult result= mallSearchService.search(searchParam);
        model.addAttribute("result",result);
        return "list";
    }


}
